package com.hdl.utils;

/**
 * 类名 HttpProtocolUtils
 * 描述 Http协议工具类
 *
 * @author hedonglin
 * @version 1.0
 * @date 2020/5/25 17:16
 */
public class HttpProtocolUtils {
    /**
     * 为响应码200提供请求头信息
     * @return
     */
    public static String getHttpHeader200(long contentLength){
        return "HTTP/1.1 200 OK \n" +
                "Content-Type: text/html \n" +
                "Content-Length: " + contentLength + " \n" +
                "\r\n"
                ;
    }


    /**
     * 为响应码404提供请求头信息
     * @return
     */
    public static String getHttpHeader404(){
        String str404 = "<h1>404 not found</h1>";
        return "HTTP/1.1 404 not found \n" +
                "Content-Type: text/html \n" +
                "Content-Length: " + str404.getBytes().length + " \n" +
                "\r\n" + str404
                ;
    }
}
